/**
 * Created with IntelliJ IDEA.
 * Description:
 * https://gitee.com/li--jiaqiang/java-test.git
 * git pull
 * git pull origin master
 * git pull origin master --allow-unrelated-histories
 * User: 86187
 * Date: 2022-04-26
 * Time: 20:03
 */

//Scanner scan = new Scanner(System.in);

public class TestDemo1 {

    /**
     * 求二进制中1的个数
     * 法 2 :
     * @param args
     */
    public static void main(String[] args) {

        int n = 7;
        int count = 0;
        while(n != 0) {
            n = n & (n-1);
            count++;
        }
        System.out.println(count);
    }


    /**
     * 求二进制中1的个数
     * :法1：
     * @param args
     */
    public static void main1(String[] args) {
        int n = 10;
        int count = 0;
        while(n != 0) {
            if((n & 1) != 0) {
                count++;
            }
            n = n >>> 1;
        }
        System.out.println(count);
    }
}
